Ext.onReady(function() {
	var toolBar = new Ext.Toolbar({});
	var menuRoot = new Ext.tree.TreeNode({text: '菜单'});
	
	function createTreeNode(nodeName, nodeAction, icon) {
		var node = new Ext.tree.TreeNode({
			text: nodeName,
			icon: icon,
			listeners: {
				"click" : function(node, event) {
					event.stopEvent();
					centerPanel.setTitle('当前位置: ' + nodeName);
					centerPanel.update({
						html: '<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="' + nodeAction + '"></iframe>'
					});
				}
			}
		});
		return node;
	}
	
	
	toolBar.add(new Ext.form.Label({
		text: '猫财签证系统'
	}));
	toolBar.addFill();
	
	toolBar.addButton(new Ext.Toolbar.Button({
		text: '签证管理',
		handler: function() {
			menuRoot.removeAll();
			centerPanel.setTitle('当前位置: 欢迎');
			centerPanel.update({
				html: '<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="welcome.html"></iframe>'
			});
			
			var baseDataNode = createTreeNode('常识管理', 'visa/knowledge.html', 'images/menu.gif');
			menuRoot.appendChild(baseDataNode);
			
			var continentNode = createTreeNode('大洲管理', 'visa/continents.html', 'images/menu.gif');
			menuRoot.appendChild(continentNode);
			
			var countryNode = createTreeNode('国家签证', 'visa/VisaCountry.html', 'images/menu.gif');
			menuRoot.appendChild(countryNode);
			
			var newsNode = createTreeNode('最新公告', 'visa/notice.html', 'images/menu.gif');
			menuRoot.appendChild(newsNode);
//			var fckTestNode = createTreeNode('FCK测试', 'test/FCKTest.jsp');
//			menuRoot.appendChild(fckTestNode);
			menuRoot.expand();
		}
	}));
	toolBar.addSpacer();
	toolBar.addSeparator();
	
	toolBar.addButton(new Ext.Toolbar.Button({
		text: '系统管理',
		handler: function() {
			menuRoot.removeAll();
			centerPanel.setTitle('当前位置: 欢迎');
			centerPanel.update({
				html: '<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="welcome.html"></iframe>'
			});
			
			var baseDataNode = createTreeNode('用户管理', 'basic/users.html', 'images/menu.gif');
			menuRoot.appendChild(baseDataNode);
			menuRoot.expand();
		}
	}));
	toolBar.addSpacer();
	toolBar.addSeparator();
	toolBar.addButton(new Ext.Toolbar.Button({
		text: '退出登录',
		handler: function() {
			Ext.MessageBox.confirm('提示',"确定退出登录？？", function(btn) {
				if(btn != 'yes') {
					return;
				}
				
				Ext.Ajax.request({
					method: 'POST',
					url: '/MeowcashVisa/admin/basic/LoginAction/logout.action',
					success:function(resp){
						var obj=Ext.util.JSON.decode(resp.responseText);
				      	if(obj.result == 'success') {
				      		window.location.href = 'index.html';
				      	}
				      	else {
				      		Ext.MessageBox.alert('报错了！！！', '错误！！！');
				      	}
					}
				})
			});
		}
	}));
	
	toolBar.render("north-div");
	
	var menuTree = new Ext.tree.TreePanel({
		rootVisible:false
	});
	menuTree.setRootNode(menuRoot);
	
	var westPanel = new Ext.Panel({
		region: 'west',
		contentEl: 'west-div',
		split : true,// 为true时，布局边框变粗 ,默认为false
		border : false,
		collapsible : false,
		collapsed : false,// 初始化是否显示, 默认是显示
		width : 150,
		minSize : 10,// 最小宽度
		maxSize : 300,
		layout : 'accordion',
		items : [
			{
				title : '功能列表',
				iconCls : 'money_box',// 字面板样式
				layout : "fit",
				items : menuTree
			}
		],
		buttons: [
          {
          	text: '生成前台',
          	handler: function() {
          		Ext.MessageBox.confirm('提示',"确定生成所有前台？？", function(btn) {
					if(btn != 'yes') {
						return;
					}
					
					generatFront();
          		});
          	}
          }
		]
	});
	
	var centerPanel = new Ext.Panel({
		title: '当前位置: 欢迎',
		region: 'center',
		contentEl: 'center-div',
		border: true,
		collapsible: false,
		html: '<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src="welcome.html"></iframe>'
	});
	
	var mainViewPort = new Ext.Viewport({
		layout: 'border',
		items:[
			{
				region: 'north',
				contentEl: 'north-div',
				border: true,
				collapsible: false
			},
			westPanel,
			centerPanel
		]
	});
	
	function generatFront() {
		Ext.Ajax.request({
			method: 'post',
			url: '../admin/visa/GeneratFrontAction/generatFront.action',
		   	success:function(resp){
		    	var obj=Ext.util.JSON.decode(resp.responseText);
		      	if(obj.result == 'success') {
		      		Ext.MessageBox.alert('提示', '生成成功！路径：C:\MeowcashVisa');
		      	}
		      	else {
		      		Ext.MessageBox.alert('报错了！！！', '生成失败！！！');
		      	}
		    }
		});
	}
	
});